import { InjectionKey } from 'vue';
import {
  createStore,
  createLogger,
  useStore as baseUseStore,
  Store
} from 'vuex';
import index, { IState } from './modules';
import demoModule, { IState as IemoModuleState } from './modules/demoModule';

const debug = process.env.NODE_ENV !== 'production';
export default createStore({
  plugins: debug ? [createLogger()] : [],
  // state: {},
  // mutations: {},
  // actions: {},
  ...index,
  modules: {
    demoModule
  },
  strict: debug
});

export const key: InjectionKey<Store<
  IState & { demoModule: IemoModuleState }
>> = Symbol();

export function useStore() {
  return baseUseStore(key);
}
